package cn.szx.boot.cms.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 未登录拦截器,跳转至登录页
 * @author jiangyl@szixing.cn
 * @date 2018/4/17 0017 下午 4:26
 * @visor
 */
public class SessionInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,Object o)throws Exception{
        //登录页无需拦截
        if(request.getRequestURI().equals("/user/login")||request.getRequestURI().equals("/user/login_view") ){
            return true;
        }
        //验证session
        Object obj = request.getSession().getAttribute("_session_user");
        if(null == obj){
            response.sendRedirect("/user/login_view");
            return false;
        }
        return true;
    }

}
